<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Chapter extends Model
{
    use HasFactory;
    use SoftDeletes;
    protected $fillable = ['course_id','title','desc','sort'];
    protected $hidden = ['created_at','updated_at','deleted_at'];


    // 添加数据关联多对多
    public function resource(){
        return $this->belongsToMany('App\Models\Resource','chapter_resources')
        ->orderBy('sort','asc')
        ->withPivot('sort')
        ->withTimestamps();
    }
}
